<template >
    <div class="banner">
        <ul class="imgs" ref="ban" @:mouseenter="enter" @:mouseleave="leave">
            <li :class="{active:now===0}">1</li>
            <li :class="{active:now===1}">2</li>
            <li :class="{active:now===2}">3</li>
            <li :class="{active:now===3}">4</li>
        </ul>
        <ul class="btns">
            <li :class="{btn_active:now===0}" @:click="change(0)"></li>
            <li :class="{btn_active:now===1}" @:click="change(1)"></li>
            <li :class="{btn_active:now===2}" @:click="change(2)"></li>
            <li :class="{btn_active:now===3}" @:click="change(3)"></li>
        </ul>
        <div class="prev" @:click="prev()">&lt</div>
        <div class="next" @:click="next()">&gt</div>
    </div>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue"
let now = ref(0);
let interval = ref(null);
function change(i) {
    now.value = i;
}
function prev() {
    let now = now.value - 1;
    if (now === -1) { now = 3; }
    now.value = now;
}
function next() {
    let now = now.value + 1;
    now %= 4;
    now.value = now;
}
function swap() {
    let n = now.value + 1;
    n %= 4;
    now.value = n;
}
function set() {
    interval.value = setInterval(swap, 3000);
}
function enter() {
    clearInterval(interval.value);
}
function leave() {
    set();
}
onMounted(()=>{
    set();
}) 
</script>
<style>
    ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .banner {
            width: 1200px;
            height: 500px;
            background-color: pink;
            position: relative;
            margin: 0 auto;
        }

        .imgs {
            width: 100%;
            height: 100%;
            background-color: antiquewhite;
        }

        .imgs li {
            width: 1200px;
            height: 500px;
            position: absolute;
            left: 0;
            top: 0;
            font-size: 50px;
            text-align: center;
            line-height: 500px;
            color: #fff;
            transition: all 1s ease-in;
            opacity: 0.1;
        }

        .imgs li:nth-child(1) {
            background-color: aqua;
            /* z-index: 1; */
        }

        .imgs li:nth-child(2) {
            background-color: blue;
        }

        .imgs li:nth-child(3) {
            background-color: chartreuse;
        }

        .imgs li:nth-child(4) {
            background-color: darkcyan;
        }

        li.active {
            opacity: 1;
            z-index: 1;
        }

        .btns {
            width: 200px;
            height: 30px;
            position: absolute;
            left: 500px;
            bottom: 20px;
            z-index: 999;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .btns li {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #ccc;
        }

        li.btn_active {
            background-color: #fff;
        }

        .prev,
        .next {
            width: 60px;
            height: 80px;
            background-color: rgba(0, 0, 0, 0.5);
            position: absolute;
            top: 210px;
            z-index: 999;
            color: #fff;
            font-size: 60px;
            line-height: 80px;
            text-align: center;
            cursor: default;
        }

        .prev {
            left: 0;
        }

        .next {
            right: 0;
        }
</style>